<template>
    <div>
        <!-- 面包屑 -->
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>用户管理</el-breadcrumb-item>
            <el-breadcrumb-item>用户列表</el-breadcrumb-item>
        </el-breadcrumb>

        <!-- 卡片 -->
        <el-card class="box-card" >
            <el-row :gutter="20">
                <el-col :span="8">
                    <el-input placeholder="请输入内容" v-model="queryinfo.query">
                        <el-button slot="append" icon="el-icon-search" @click="getUserList()"></el-button>
                    </el-input>
                </el-col>
                <el-col :span="5">
                     <el-button type="success" @click="adddialogVisible = true">添加用户</el-button>
                </el-col>
          </el-row>
           <!-- 表格区域 -->
        <el-table
            border
            :data="userList"
            stripe
            style="width: 100%">
            <el-table-column
             type="index">
            </el-table-column>
            <el-table-column
            prop="username"
            label="姓名"
            width="180">
            </el-table-column>
            <el-table-column
            prop="email"
            label="邮箱">
            </el-table-column>
            <el-table-column
            prop="mobile"
            label="电话">
            </el-table-column>
            <el-table-column
            prop="role_name"
            label="角色">
            </el-table-column>
            <el-table-column
            label="用户状态">
            <el-switch
              @change="getSdateList(scope.row.mg_state,scope.row.id)"
              slot-scope="scope"
              v-model="scope.row.mg_state"
              >
            </el-switch>
            </el-table-column>
            <el-table-column
            width="185"
            label="操作">
            <template slot-scope="scope">
                <el-button type="primary" icon="el-icon-edit" size="mini" @click="ShowEdit(scope)"></el-button>
                <el-button type="danger" icon="el-icon-delete" size="mini" @click="remove(scope)"></el-button>
                <el-tooltip class="item" effect="dark" content="分配权限" placement="top" :enterable="false">
                  <el-button type="warning" icon="el-icon-share" size="mini"></el-button>
                </el-tooltip>
            </template>
            </el-table-column>
        </el-table>
            <!-- 分页 -->
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="queryinfo.pagenum"
              :page-sizes="[2,5,10]"
              :page-size="queryinfo.pagesize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total">
            </el-pagination>
        </el-card>
        <!-- 添加的模态框 -->
        <el-dialog
          title="添加用户"
          :visible.sync="adddialogVisible"
          @close="addDialogClosed"
          width="50%">
          <!-- 添加对话框的表单 -->
          <el-form :model="addruleForm" :rules="addrules" ref="addruleFormRef"  label-width="70px" >
            <el-form-item label="用户名" prop="username">
              <el-input v-model="addruleForm.username"></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="password">
              <el-input v-model="addruleForm.password"></el-input>
            </el-form-item>
            <el-form-item label="邮箱" prop="email">
              <el-input v-model="addruleForm.email"></el-input>
            </el-form-item>
            <el-form-item label="手机" prop="mobile">
              <el-input v-model="addruleForm.mobile"></el-input>
            </el-form-item>
          </el-form>
          <span slot="footer" class="dialog-footer">
            <el-button @click="adddialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="addUser">确 定</el-button>
          </span>
        </el-dialog>
        <!-- 编辑的对话框 -->
        <el-dialog
          title="编辑用户"
          :visible.sync="EditdialogVisible"
          @close="EditdialogVisibleClose"
          width="50%">
          <el-form :model="EditruleForm" :rules="Editrules" ref="EditruleFormRef" label-width="100px" class="demo-ruleForm">
            <el-form-item label="用户名" prop="username">
              <el-input v-model="EditruleForm.username" disabled></el-input>
            </el-form-item>
            <el-form-item label="邮箱" prop="email">
              <el-input v-model="EditruleForm.email"></el-input>
            </el-form-item>
            <el-form-item label="手机" prop="mobile">
              <el-input v-model="EditruleForm.mobile"></el-input>
            </el-form-item>
          </el-form>
          <span slot="footer" class="dialog-footer">
            <el-button @click="EditdialogVisible=false">取 消</el-button>
            <el-button type="primary" @click="EditUser">确 定</el-button>
          </span>
        </el-dialog>
    </div>
</template>
<script>
import mix from './Users-mixins.js'
export default {
  mixins: [mix]
}
</script>
<style lang="less" scoped>
.box-card {
  margin-top: 15px;
}
.el-table {
  margin-top: 10px;
}
.el-pagination {
  margin-top: 10px;
}
</style>
